package com.example.common.exception;

import com.example.common.enums.HttpResponseEnum;
import lombok.Getter;

/**
 * 自定义业务异常
 */
@Getter
public class ServiceException extends RuntimeException {

    /**
     * 错误码
     */
    private final int code;

    public ServiceException(int code, String message) {
        super(message);
        this.code = code;
    }

    public ServiceException(HttpResponseEnum httpResponseEnum) {
        super(httpResponseEnum.getMessage());
        this.code = httpResponseEnum.getCode();
    }

    public ServiceException(HttpResponseEnum httpResponseEnum, String message) {
        super(message);
        this.code = httpResponseEnum.getCode();
    }

    public ServiceException(String message) {
        super(message);
        this.code = HttpResponseEnum.OPERATION_ERROR.getCode();
    }
}
